package com.mrd.gtimp.base.entity;

import org.hibernate.annotations.GenericGenerator;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

@Entity
@Table(name = "T_SYS_DEPT")
public class Dept implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(generator = "paymentableGenerator")
    @GenericGenerator(name = "paymentableGenerator", strategy = "uuid")
    @Column(name = "DEPT_ID")
    private String id;

    @Column(name = "DEPT_NAME")
    private String name;

    @Column(name = "DEPT_ISABLED")
    private String isabled;

    @Column(name = "DEPT_STATE")
    private String state;

    @Column(name = "CREATOR")
    private String creator;

    @Column(name = "CTIME")
    @Temporal(TemporalType.TIMESTAMP)
    private Date ctime;

    @Column(name = "MODIFIER")
    private String modifier;

    @Column(name = "MTIME")
    @Temporal(TemporalType.TIMESTAMP)
    private Date mtime;

    @ManyToOne
    @JoinTable(name = "T_SYS_COM_DEPT", joinColumns = @JoinColumn(name = "DEPT_ID"),
            inverseJoinColumns = @JoinColumn(name = "COM_ID"))
    private Company company;

    @ManyToMany(targetEntity = User.class)
    @JoinTable(name = "T_SYS_DEPT_USER", joinColumns = @JoinColumn(name = "DEPT_ID"),
            inverseJoinColumns = @JoinColumn(name = "U_ID"))
    private List<User> users;

    @Transient
    private String isParent;

    public Dept() {
        super();
    }

    public Company getCompany() {
        return company;
    }

    public void setCompany(Company company) {
        this.company = company;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getIsabled() {
        return isabled;
    }

    public void setIsabled(String isabled) {
        this.isabled = isabled;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public String getCreator() {
        return creator;
    }

    public void setCreator(String creator) {
        this.creator = creator;
    }

    public Date getCtime() {
        return ctime;
    }

    public void setCtime(Date ctime) {
        this.ctime = ctime;
    }

    public String getModifier() {
        return modifier;
    }

    public void setModifier(String modifier) {
        this.modifier = modifier;
    }

    public Date getMtime() {
        return mtime;
    }

    public void setMtime(Date mtime) {
        this.mtime = mtime;
    }

    public List<User> getUsers() {
        return users;
    }

    public void setUsers(List<User> users) {
        this.users = users;
    }

    public String getIsParent() {
        return isParent;
    }

    public void setIsParent(boolean isParent) {
        this.isParent = String.valueOf(isParent);
    }

    @Override
    public String toString() {
        return "{id:" + id + ",name:" + name + ",isParent:" + isParent + "}";
    }
}
